package com.itnoob.controller;

import cn.hutool.extra.spring.SpringUtil;
import com.itnoob.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhoujun
 * @date 2024/12/7 10:03
 *
 * springboot中使用装饰者模式来给任何一个service添加日志功能,并利用依赖注入来动态的选择被装饰者的对象
 * UserController:处理用户相关的请求
 * decorator --> logUserService,authUserService ,logAndAuthUserService
 */
@RestController
public class UserController {

    @RequestMapping("/user")
    public String getUser(@RequestParam("id") int id,@RequestParam("decorator") String decorator){
        //调用userService的方法来获取用户,实现日志功能
        UserService userService = SpringUtil.getBean(decorator);
        return userService.getUserName(id);

    }

}
